package com.ruoyi.project.oms.paeaAuAuditGroupUserRel.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.oms.paeaAuAuditGroupUserRel.domain.PaeaAuAuditGroupUserRel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.oms.paeaAuAuditGroupUserRel.mapper.PaeaAuAuditGroupUserRelMapper;
import com.ruoyi.project.oms.paeaAuAuditGroupUserRel.service.IPaeaAuAuditGroupUserRelService;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import java.util.Arrays;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
/**
 * 监督小组人员Service业务层处理
 *
 * @author gang.wei
 * @date 2020-03-23
 */
@Service
@Slf4j
public class PaeaAuAuditGroupUserRelServiceImpl extends ServiceImpl<PaeaAuAuditGroupUserRelMapper, PaeaAuAuditGroupUserRel> implements IPaeaAuAuditGroupUserRelService
{
    @Autowired
    private PaeaAuAuditGroupUserRelMapper paeaAuAuditGroupUserRelMapper;

    /**
     * 查询监督小组人员
     *
     * @param id 监督小组人员ID
     * @return 监督小组人员
     */
    @Override
    public PaeaAuAuditGroupUserRel selectPaeaAuAuditGroupUserRelById(String id)
    {
        return paeaAuAuditGroupUserRelMapper.selectAuditGroupAssignUserById(id);
    }

    /**
     * 查询监督小组人员列表
     *
     * @param paeaAuAuditGroupUserRel 监督小组人员
     * @return 监督小组人员
     */
    @Override
    public List<PaeaAuAuditGroupUserRel> selectPaeaAuAuditGroupUserRelList(PaeaAuAuditGroupUserRel paeaAuAuditGroupUserRel)
    {
        return paeaAuAuditGroupUserRelMapper.selectPaeaAuAuditGroupUserRelList(paeaAuAuditGroupUserRel);
    }

    @Override
    public List<PaeaAuAuditGroupUserRel> selectPaeaAuAuditGroupUserRelListByGroupId(String groupId) {
        return paeaAuAuditGroupUserRelMapper.findAuditGroupByGroupId(groupId);
    }

    /**
     * 新增监督小组人员
     *
     * @param paeaAuAuditGroupUserRel 监督小组人员
     * @return 结果
     */
    @Override
    public int insertPaeaAuAuditGroupUserRel(PaeaAuAuditGroupUserRel paeaAuAuditGroupUserRel)
    {
        return paeaAuAuditGroupUserRelMapper.insertPaeaAuAuditGroupUserRel(paeaAuAuditGroupUserRel);
    }

    /**
     * 修改监督小组人员
     *
     * @param paeaAuAuditGroupUserRel 监督小组人员
     * @return 结果
     */
    @Override
    public int updatePaeaAuAuditGroupUserRel(PaeaAuAuditGroupUserRel paeaAuAuditGroupUserRel)
    {
        return paeaAuAuditGroupUserRelMapper.updatePaeaAuAuditGroupUserRel(paeaAuAuditGroupUserRel);
    }

    /**
     * 删除监督小组人员对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePaeaAuAuditGroupUserRelByIds(String ids)
    {
        return paeaAuAuditGroupUserRelMapper.deletePaeaAuAuditGroupUserRelByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除监督小组人员信息
     *
     * @param id 监督小组人员ID
     * @return 结果
     */
    @Override
    public int deletePaeaAuAuditGroupUserRelById(String id)
    {
        return paeaAuAuditGroupUserRelMapper.deletePaeaAuAuditGroupUserRelById(id);
    }

    @Override
    public List<PaeaAuAuditGroupUserRel> auditGroupAssignUserConfigSave(String groupId, String ids) {
        if (!StringUtils.isNull(groupId)) {
            this.remove(new UpdateWrapper<PaeaAuAuditGroupUserRel>().eq("group_id", groupId));
        }
        List<PaeaAuAuditGroupUserRel> paeaAuAuditGroupUserRelList = Lists.newArrayList();
        if (!StringUtils.isEmpty(ids)) {
            Arrays.stream(Convert.toStrArray(ids)).forEach(id -> {
                PaeaAuAuditGroupUserRel paeaAuAuditGroupUserRel = new PaeaAuAuditGroupUserRel();
                paeaAuAuditGroupUserRel.setGroupId(groupId);
                String[] auditor = id.split("@@@");
                paeaAuAuditGroupUserRel.setAuditor(auditor[0]);
                paeaAuAuditGroupUserRel.setAuditorNam(auditor[1]);
                paeaAuAuditGroupUserRel.setStatus(0);
                paeaAuAuditGroupUserRelList.add(paeaAuAuditGroupUserRel);
            });
            this.saveBatch(paeaAuAuditGroupUserRelList);
            int addCount = paeaAuAuditGroupUserRelList.size();
            log.info(String.format("监控小组人员分配成功：insert[%s]", addCount));
        }
        return paeaAuAuditGroupUserRelList;
    }
}
